package com.zxl.openapi.controller;

import com.zxl.openapi.bean.ApiInfoBean;
import com.zxl.openapi.constans.SystemParameter;
import com.zxl.openapi.feign.RedisService;
import com.zxl.openapi.mq.SendMessageChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;



@RestController
@RequestMapping("/web")
public class WebMasterStartController {

    @Autowired
    private SendMessageChannel sendMessageChannel;

    @Autowired
    private RedisService redisService;

    @PostMapping("/update")
    public String updateApiInfo(@RequestBody Map<String,String> apiInfoBean){

        String method = apiInfoBean.get("method");
        //因为method是key，而不是具体的属性和值 不需要保留
        apiInfoBean.remove("method");

        System.out.println(method);

        System.out.println(SystemParameter.REDIS_APIPRE + method);

        System.out.println(apiInfoBean);

        redisService.mPut(SystemParameter.REDIS_APIPRE + method,apiInfoBean);

        System.out.println(SystemParameter.REDIS_APIPRE + method);


        //发送mq
        MessageChannel channel = sendMessageChannel.messageChannel();

        channel.send(new GenericMessage<String>("听说太理想的恋爱终不可接触 "));

        return "WebMasterStartController success";

    }

}
